﻿//var ss = {
//    AddressCode: false,
//    BoundRate: BoundRate,
//    ChannelId: 5,
//    ChannelName: null,
//    ChannelNum: 1,
//    ChannelStatus: 0,
//    ComPort: 0,
//    Comment: null,
//    DirectionSpeed: 0,
//    DirectionTime: 0,
//    IsAutoTracking: true,
//    IsCameraShot: false,
//    IsDirection: false,
//    IsDirectionPanRev: false,
//    IsDirectionTiltRev: false,
//    IsRecord: false,
//    IsSoundCollect: false,
//    MonitorHostId: null,
//    PTZProtocol: null,
//    PreSetNums: null,
//    RecordTime: null,
//    UserGroupId: null,
//    VideoAgt: null
//};



    function Serialize(obj) {
        switch (obj.constructor) {
            case Object:
                var str = "{";
                for (var o in obj) {
                    if (obj[o])
                        str += String.fromat("\"{0}\":{1}", o, Serialize(obj[o]));
                    else
                        str += String.fromat("\"{0}\":{1}", o, ":null,");
                }
                if (str.substr(str.length - 1) == ",")
                    str = str.substr(0, str.length - 1);
                return str + "}";
                break;
            case Array:
                var str = "[";
                for (var o in obj) {
                    str += Serialize(obj[o]) + ",";
                }
                if (str.substr(str.length - 1) == ",")
                    str = str.substr(0, str.length - 1);
                return str + "]";
                break;
            case Boolean:
                return obj.toString();
                break;
            case Date:
                return "\"" + obj.toString() + "\"";
                break;
            case Function:
                break;
            case Number:
                return obj.toString();
                break;
            case String:
                return "\"" + obj.toString() + "\"";
                break;
        }
    }
    function GetCurrentChannel() {
        
    }
     
    function SetDefaultValue() {
        $(".editContainer [def]").each(function() {
            var def = $(this).attr("def");
            var type = this.type;
            switch (type) {
                case "text":
                    this.value = def == "null" ? "" : def;
                    break;
                case "checkbox":
                    this.checked = def == "true";
                    break;
                //                case "select-on": 
                //                    this.checked = def == "true"; 
                //                    break; 
            }
        });
    }
</script>
<script>

   

    function Add() {
    }
    
    var channelList = new Array();

    $(document).ready(function() {
        $.formValidator.initConfig({ formid: document.forms[0].id, onerror: function(msg) { }, onSuccess: function() { alert(); Add(); return false; } });    //初始化，必需
        $(".roleName").formValidator({ tipid: "roleNameTip", onshow: "", onfocus: "", oncorrect: " " })
        
        $(".Add").click(function() {
            channelList.push(GetCurrentChannel());
            SetUI();
        });
        $(".Clear").click(function() {
            SetDefaultValue();
        });
    });

       function SetUI() {
            var tab = $("#tabChannelEdit")[0];
            $(tab).find("tr[name='row']").remove();
            var templateTR = $(tab).find("tr[name='tabTemplate']")[0];
            var index = 0;
            $(channelList).each(function() {
                index++;
                var templateHTML = String.format("<tr class='row{0}' name=\"row\">{1}</tr>",
                 index % 2 == 0 ? "0" : "1", $(templateTR).html());
                var s = this;
                s.ChannelNum = index;
                if (s.ChannelName == null)
                    s.ChannelName = "通道" + index;
                var va = s.NetVideoAgt;
                
                var html = String.format(templateHTML,
                s.ChannelNum, s.ChannelName, GetStatusName(s.ChannelStatus),
                GetBoolIcon(s.IsRecord), s.RecordTime,
                GetBoolIcon(s.IsDirection), GetBoolIcon(s.IsCameraShot), GetBoolIcon(s.IsAutoTracking), GetBoolIcon(s.IsSoundCollect),
                s.DirectionSpeed, s.DirectionTime, s.ComPort, va.QS, va.RT, va.HT, va.WT);
                $(tab).append(html);
            });
        }

        function GetSelectValue(objId) {
            var id =objId;
            var ops = $("#" + id)[0].options;
            for (var i = 0; i < ops.length; i++) {
                if (ops[i].selected)
                    return ops[i].value;
            }
        }
        
    function GetStatusName(value) {
        return value;
    }
    function GetBoolIcon(value){
        return value ? "011906263.gif" : "011906259.gif";
    }
    function SetTabStyle() {
    }


    function tc() {
        var that = this;
        this.Type = 0; //0添加，1修改
        var tabContainer = $(".tabContainer");
        this.SetDefaultValue = function() {
            tabContainer.find("[def]").each(function() {
                var def = $(this).attr("def");
                var type = this.type;
                switch (type) {
                    case "text":
                        this.value = def == "null" ? "" : def;
                        break;
                    case "checkbox":
                        this.checked = def == "true";
                        break;
                    //                case "select-on":  
                    //                    this.checked = def == "true";  
                    //                    break;  
                }
            });
        };
        this.Add = function() {
            
        };
        this.Edit = function(value) {
            tabContainer.find("[type='Add']").hide();
            tabContainer.find("[type='Edit']").show();
        };
        this.GetValue = function() {
            return {
                ChannelNum: $("#txtChannelNum").val(), //通道数量
                AddressCode: $("#txtAddressCode").val(), //地址码
                BoundRate: $("#txtBoundRate").val(), //波特率
                ChannelName: null, //通道名
                ChannelStatus: GetStatusValue("ddlStatus"), //状态
                ComPort: $("#txtComPort").val(), //云台控制端口
                DirectionSpeed: $("#txtDirectionSpeed").val(), //云台控制速度
                DirectionTime: $("#txtDirectionTime").val(), //云台控制时间
                IsAutoTracking: $("#cbIsAutoTracking")[0].checked, //自动跟踪
                IsCameraShot: $("#cbIsCameraShot")[0].checked, //镜头功能
                IsDirection: $("#cbIsDirection")[0].checked, //云台功能
                IsDirectionPanRev: $("#cbIsDirectionPanRev")[0].checked, //上下反转
                IsDirectionTiltRev: $("#cbIsDirectionTiltRev")[0].checked, //左右反转
                IsRecord: $("#cbIsRecord")[0].checked, //开启录制
                IsSoundCollect: $("#cbIsSoundCollect")[0].checked, //声音采集
                PTZProtocol: $("#txtPTZProtocol").val(), //协议
                PreSetNums: $("#txtPreSetNums").val(), //预置位
                RecordTime: $("#txtRecordTime").val(), //录制时间
                NetVideoAgt: {//网络视频参数
                    QS: $("#txtNetQS").val(),
                    RT: $("#txtNetRT").val(),
                    WT: $("#txtNetWT").val(),
                    HT: $("#txtNetHT").val()
                },
                MBVideoAgt: {//手机视频参数
                    QS: $("#txtMBQS").val(),
                    RT: $("#txtMBRT").val(),
                    WT: $("#txtMBWT").val(),
                    HT: $("#txtMBHT").val()
                }
            };
        };
        
    }

 